﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace roma
{
    internal class Basefunction
    {
        Tips tips = new Tips();
        Calcution calcution = new Calcution();
        public string once_number_checkchanged(string checkchanged_judge)
        {
            return checkchanged_judge;
        }
        public int arab_toint(string arab)
        {
            int arab_toint = int.Parse(arab);
            return arab_toint;
        }
        public string turn_function(string arab, string checkchanged_judge,string path,string filename)
        {
            if (checkchanged_judge == null)
            {
                tips.error_message_show(1001);
                return "1001";
            }
            else if (arab == "")
            {
                tips.error_message_show(1002);
                return "1002";
            }
            else if (checkchanged_judge == "once")
            {
                int arab_out = arab_toint(arab);
                string roma_out = calcution.toroma(arab_out);
                if (roma_out == "超出计算范围")
                {
                    tips.error_message_show(1003);
                    return "1003";
                }
                return roma_out;
            }
            else if (checkchanged_judge == "numberous")
            {
                OpenOrCreateFile(path, filename);
                //仅能实现打开文件，其余的待实现
                return "";
            }
            else
            {
                tips.error_message_show(1000);
                return "1000";
            }
        }

        public void OpenOrCreateFile(string path, string fileName)
        {
            // 拼接文件完整路径
            string filePath = Path.Combine(path, fileName);

            // 检查文件是否存在
            if (File.Exists(filePath))
            {
                // 使用默认关联程序打开文件
                Process.Start(filePath);
            }
            else
            {
                // 创建新文件
                using (File.Create(filePath)) { }
                // 打开新文件
                Process.Start(filePath);
            }

        }
    }
}

